package com.boho.ecp.manage.product.service;

import java.sql.Connection;
import java.util.Date;

import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.po.Pager;

import com.boho.ecp.constant.Product;
import com.boho.ecp.manage.product.dao.ProductDao;
import com.boho.ecp.po.TProductPO;
import com.boho.ecp.product.cache.TPlateProductCache;

public class ProductService {

	/**
	 * 分页查询商品信息
	 * @param con
	 * @param pager
	 * @param productName
	 * @return
	 * @throws Exception
	 */
	public static ComboPager queryProductPager(Connection con, Pager pager, String productName, String status) throws Exception{
		ComboPager cp = ProductDao.queryProductPager(con, pager, productName, status);
		return cp;
	}
	
	/**
	 * 修改商品信息
	 * @param con
	 * @param productId
	 * @param status
	 * @param operator
	 * @throws Exception
	 */
	public static void updateProductStatus(Connection con, Integer productId, String status, Integer operator) throws Exception{
		TProductPO cPO = new TProductPO();
		TProductPO vPO = new TProductPO();
		cPO.setProductId(productId);
		vPO.setProductStatus(status);
		vPO.setUpdateBy(operator.toString());
		vPO.setUpdateDate(new Date());
		POUtils.update(con, cPO, vPO, false);
		
		TPlateProductCache.queryTPlateProductRemove();
	}
	
	/**
	 * 删除商品
	 * @param con
	 * @param productId
	 * @param operator
	 * @throws Exception
	 */
	public static void deleteProductById(Connection con, Integer productId, Integer operator) throws Exception{
		TProductPO cPO = new TProductPO();
		TProductPO vPO = new TProductPO();
		cPO.setProductId(productId);
		vPO.setIsValid(Product.INVALID);
		vPO.setUpdateBy(operator.toString());
		vPO.setUpdateDate(new Date());
		POUtils.update(con, cPO, vPO, false);
		
		TPlateProductCache.queryTPlateProductRemove();
	}
}
